<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="反馈类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="反馈类型" clearable>
          <el-option v-for="dict in dict.type.app_feedback_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="审核状态" clearable>
          <el-option v-for="dict in dict.type.app_check_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="爱洞ID" prop="platformId">
        <el-input v-model="queryParams.platformId" placeholder="请输入爱洞ID" clearable
                  @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userFeedbackList" >
      <el-table-column label="爱动ID" align="center" prop="platformId">
        <template slot-scope="scope">
          <a v-if="scope.row.sex === 1" style="color: #FF6EC7" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
          <a v-else style="color: #7099F9" @click="toUserInfo(scope.row.platformId)">{{ scope.row.platformId }}
          </a>
        </template>
      </el-table-column>
      <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_feedback_type" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_check_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="内容" align="center" prop="content" />
      <el-table-column label="联系方式" align="center" prop="contract" />
      <el-table-column label="图片" align="center" prop="images" >
        <template slot-scope="scope">
        <ImagePreview :src="scope.row.images" width="100px" height="100px"></ImagePreview>
        </template>
      </el-table-column>
      <el-table-column label="反馈时间" align="center" prop="createTime" />
      <el-table-column label="审核备注" align="center" prop="remark" />
      <el-table-column label="审核人" align="center" prop="updateBy" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button :disabled="scope.row.status!=1" size="mini" type="text" icon="el-icon-check"
            @click="handlePass(scope.row)" v-hasPermi="['system:userFeedback:pass']">审核通过</el-button>
          <el-button :disabled="scope.row.status!=1" size="mini" type="text" icon="el-icon-close"
            @click="handleRefuse(scope.row)" v-hasPermi="['system:userFeedback:refuse']">审核拒绝</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 通过审核 -->
    <el-dialog title="审核通过" :visible.sync="openPass" width="500px" append-to-body>
      <el-form ref="form" :model="bo" :rules="rules" label-width="80px">
        <el-form-item label="处理意见" prop="reason">
          <el-input v-model="bo.reason" placeholder="请输入操作备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="toPass">确 定</el-button>
        <el-button @click="openPass=false">取 消</el-button>
      </div>
    </el-dialog>


    <!--拒绝审核 -->
    <el-dialog title="审核拒绝" :visible.sync="openRefuse" width="500px" append-to-body>
      <el-form ref="form" :model="bo" :rules="rules" label-width="80px">
        <el-form-item label="处理意见" prop="reason">
          <el-input v-model="bo.reason" placeholder="请输入操作备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="toRefuse">确 定</el-button>
        <el-button @click="openRefuse=false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUserFeedback, getUserFeedback, delUserFeedback, addUserFeedback, updateUserFeedback,pass,refuse } from "@/api/service/sys/userFeedback";

export default {
  name: "UserFeedback",
  dicts: ['app_feedback_type','app_check_status'],
  data() {
    return {
      bo: {},
        openRefuse: false,
        openPass: false,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 反馈表格数据
      userFeedbackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: '1',
        platformId: undefined,
        type: undefined,
        content: undefined,
        contract: undefined,
        imgs: undefined,
        userId: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "自增主键不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "类型不能为空", trigger: "change" }
        ],
        content: [
          { required: true, message: "内容不能为空", trigger: "blur" }
        ],
        contract: [
          { required: true, message: "联系方式不能为空", trigger: "blur" }
        ],
        imgs: [
          { required: true, message: "图片不能为空", trigger: "blur" }
        ],
        userId: [
          { required: true, message: "用户id不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
     /** 审核通过 */
     handlePass(row) {
        this.bo.id = row.id
        this.openPass = true;
      },

      /** 删除按钮操作 */
      handleRefuse(row) {
        this.bo.id = row.id
        this.openRefuse = true;
      },
      toPass() {
        pass(this.bo).then(response => {
          this.$modal.msgSuccess("操作成功");
          this.openPass = false;
          this.getList();
        }).finally(() => {
          this.buttonLoading = false;
        });
      },
      toRefuse() {
        refuse(this.bo).then(response => {
          this.$modal.msgSuccess("操作成功");
          this.openRefuse = false;
          this.getList();
        }).finally(() => {
          this.buttonLoading = false;
        });
      },
    /** 查询反馈列表 */
    getList() {
      this.loading = true;
      listUserFeedback(this.queryParams).then(response => {
        this.userFeedbackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        type: undefined,
        content: undefined,
        contract: undefined,
        imgs: undefined,
        userId: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加反馈";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getUserFeedback(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.title = "修改反馈";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.form.id != null) {
            updateUserFeedback(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addUserFeedback(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除反馈编号为"' + ids + '"的数据项？').then(() => {
        this.loading = true;
        return delUserFeedback(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/userFeedback/export', {
        ...this.queryParams
      }, `userFeedback_${new Date().getTime()}.xlsx`)
    },

    /**
     * 点击用户爱动id跳转到用户页面
     * @param platformId
     */
    toUserInfo(platformId) {
      this.$router.push({path: "/user/appUser", query: {id: platformId}});
    }
  }
};
</script>
